package com.wutuo.aggragation.expire.controller;

import cn.apestar.agg.common.security.BaseAuthController;
import com.wutuo.aggragation.expire.dto.RosterExpireInfoDto;
import com.wutuo.aggragation.expire.request.ExpireManagementAddRequest;
import com.wutuo.aggragation.expire.request.ExpireManagementLatestListRequest;
import com.wutuo.aggragation.expire.request.ExpireManagementListRequest;
import com.wutuo.aggragation.expire.response.ExpireManagementLatestResponse;
import com.wutuo.aggragation.expire.response.ExpireManagementResponse;
import com.wutuo.aggragation.expire.service.ExpireManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/expireManagement", produces = "application/json;charset=UTF-8")
public class ExpireManagementController extends BaseAuthController {

    @Autowired
    private ExpireManagementService expireManagementService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public void add(@RequestBody @Valid ExpireManagementAddRequest request) {
        expireManagementService.add(request, getCurrentUserId(), getInstitutionId());
    }

    @RequestMapping(value = "/listByRosterId", method = RequestMethod.POST)
    public List<ExpireManagementResponse> listByRosterId(@RequestBody @Valid ExpireManagementListRequest request) {
        return expireManagementService.listByRosterId(request, getInstitutionId());
    }

    @RequestMapping(value = "/listLatestByInstitutionId", method = RequestMethod.POST)
    public List<ExpireManagementLatestResponse> listLatestByInstitutionId(
            @RequestBody @Valid ExpireManagementLatestListRequest request) {
        return expireManagementService.listLatestByInstitutionId(request, getInstitutionId());
    }

    @RequestMapping(value = "/remindExpire/{roster_id}", method = RequestMethod.POST)
    public void remindExpire(@PathVariable("roster_id") Long rosterId) {
        expireManagementService.remindExpire(rosterId, getCurrentUserId(), getInstitutionId());
    }

    @RequestMapping(value = "/expire/{roster_id}", method = RequestMethod.POST)
    public RosterExpireInfoDto getRosterExpireInfoByRosterId(@PathVariable("roster_id") Long rosterId) {
        return expireManagementService.getRosterExpireInfoByRosterId(rosterId, getCurrentUser(), getInstitutionId());
    }

    @RequestMapping(value = "/delete/{expire_management_id}", method = RequestMethod.POST)
    public void delete(@PathVariable("expire_management_id") Long expireManagementId) {
        expireManagementService.deleteExpireManagement(expireManagementId, getCurrentUserId(), getInstitutionId());
    }
}
